//
//  NSObject+NullData.m
//  YBInsurance
//
//  Created by S2 on 4/11/16.
//  Copyright © 2016 YB. All rights reserved.
//

#import "NSObject+NullData.h"

@implementation NSObject (NullData)

- (BOOL)isThatNull {
    
    if ([self isEqual:[NSNull null]] || [self isKindOfClass:[NSNull class]]) {
        
        return YES;
    }
    
    if ([self isKindOfClass:[NSString class]]) {
        
        if ([(NSString *)self isEqualToString:@"<null>"] || [(NSString *)self isEqualToString:@"(null)"] || [(NSString *)self isEqualToString:@"null"]) {
            
            return YES;
        }
    }
    
    return NO;
}

+ (UIWindow*)mainWindow {
    id appDelegate = [UIApplication sharedApplication].delegate;
    if (appDelegate && [appDelegate respondsToSelector:@selector(window)]) {
        return [appDelegate window];
    }
    
    
    NSArray *windows = [UIApplication sharedApplication].windows;
    if ([windows count] == 1) {
        return [windows firstObject];
    } else {
        for (UIWindow *window in windows) {
            if (window.windowLevel == UIWindowLevelNormal) {
                return window;
            }
        }
    }
    
    return nil;
}

// 截取当前屏幕
+ (UIImage *)screenImageWithSize:(CGSize )imgSize {
    UIGraphicsBeginImageContext(imgSize);
    CGContextRef context = UIGraphicsGetCurrentContext();
    UIWindow *window = [NSObject mainWindow];
    [window.layer renderInContext:context];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
    
}


@end
